﻿using System;

namespace Gqq.CSharpindepth2.DesignPatterns.Observer
{
    public class Master : IObserver
    {
        public ISubject Subject { get; set; }

        public Master(ISubject sub)
        {
            Subject = sub;
            DoRegister();
        }

        /// <summary>
        /// 注册Action到Subject中的AniAction事件
        /// </summary>
        public void DoRegister()
        {
            Subject.Register(Acition);
        }

        /// <summary>
        /// 主人的动作
        /// </summary>
        public void Acition()
        {
            Console.WriteLine("waken...");
        }
    }

    public class Mouse : IObserver
    {
        public ISubject Subject { get; set; }

        public Mouse(ISubject sub)
        {
            Subject = sub;
            DoRegister();
        }

        /// <summary>
        /// 注册Action到Subject中的AniAction事件
        /// </summary>
        public void DoRegister()
        {
            Subject.Register(Acition);
        }

        /// <summary>
        /// 主人的动作
        /// </summary>
        public void Acition()
        {
            Console.WriteLine("running...");
        }
    }
}
